package com.ruoyi.qywx.enums;

import cn.hutool.json.JSONObject;
import com.ruoyi.common.core.cache.Meta;
import com.ruoyi.qywx.callback.events.ExtChatEvent;
import com.ruoyi.qywx.callback.events.ExternalTagEvent;
import com.ruoyi.qywx.callback.events.ExternalUserEvent;
import com.ruoyi.qywx.callback.events.QywxEvent;
import com.ruoyi.qywx.callback.txl.ExtChatEncrypt;
import com.ruoyi.qywx.callback.txl.ExternalTagEncrypt;
import com.ruoyi.qywx.callback.txl.ExternalUserEncrypt;
import com.ruoyi.qywx.service.inters.SyncQiyeService;

/**
 * @author : hcl
 * @Date : 2023/8/25 09:16
 */
public enum QyExtEventEm {
    /**
     * 外部联系人事件
     */
    CHANGE_EXTERNAL_CONTACT {
        @Override
        public QywxEvent exeternalEvent(SyncQiyeService syncService, JSONObject json, Meta meta) {
            return new ExternalUserEvent(syncService, json.toBean(ExternalUserEncrypt.class), meta);
        }
    },
    /**
     * 外部联系人标签事件
     */
    CHANGE_EXTERNAL_TAG {
        @Override
        public QywxEvent exeternalEvent(SyncQiyeService syncService, JSONObject json, Meta meta) {
            return new ExternalTagEvent(syncService, json.toBean(ExternalTagEncrypt.class), meta);
        }
    },
    /**
     * 客户群变更事件
     * 事件包含：群名变更，群成员增加或移除，群主变更，群公告变更
     * 收到该事件后，企业需要再调用获取客户群详情接口，以获取最新的群详情
     */
    CHANGE_EXTERNAL_CHAT {
        @Override
        public QywxEvent exeternalEvent(SyncQiyeService syncService, JSONObject json, Meta meta) {
            return new ExtChatEvent(syncService, json.toBean(ExtChatEncrypt.class), meta);
        }
    };

    public abstract QywxEvent exeternalEvent(SyncQiyeService syncService, JSONObject json, Meta meta);
}
